﻿

using Grishko.DataTier;
using OutdoorLib.Context;
using OutdoorLib.BaseEntity.Constraction;
namespace OutdoorLib.BaseEntity.WS
{
    public class wsConstractions :EntitySingle 
    {

        public wsConstractions()
        {

            //Uncomment the following line if using designed components 
            //InitializeComponent(); 
        }



        public ConstractionEntity GetNewConstraction(string ConstractionID)
        {
            if (!CacheTools.IsCacheObject(ConstractionID))
            {
                ConstractionEntity p = new ConstractionEntity();
                p.ID = ConstractionID;
                CacheTools.SetCacheObject(ConstractionID, p);
                return p;
            }

            return (ConstractionEntity)CacheTools.GetCacheObect(ConstractionID);

        }

      
        //public ConstractionList GetConstractionList(string Where, int StartRowIndex, int EndRowIndex)
        //{
        //    return null;
        //    //ConstractionList.sqlLoadStatment WhereStatment = new ConstractionList.sqlLoadStatment() { Lexeme = Where, StartRowIndex = StartRowIndex, EndRowIndex = EndRowIndex };
        //    //ConstractionList list = new ConstractionList { };
        //    //list.SqlStatment = WhereStatment;

        //    //list.Load();
        //    //return list;
        //}

       
        public SideListWithContracts.SideContractItemBox[] GetSideListWithContracts(SideListWithContracts.SqlLoadStatment WhereStatment)
        {
            SideListWithContracts l = new SideListWithContracts();
            l.SqlStatment = WhereStatment;
            l.Load();
            //List<SideListWithContracts.SurfaceItemBox> r = l.GetSurfaces();
            return l.ToArray<SideListWithContracts.SideContractItemBox>();
        }



        //[WebMethod(EnableSession = true)]
        //public SideList GetSideList(SideList.sqlLoadStatment WhereStatment)
        //{        
        //    SideList list = new SideList { };
        //    list.SqlStatment = WhereStatment;
        //    list.Load();
        //    return list;
        //}

      
        public SideLst GetSideLst(SideLst.sqlLoadStatment WhereStatment)
        {
            SideLst list = new SideLst { };
            list.SqlStatment = WhereStatment;
            list.Load();
            return list;
        }

        
        public SurfaceList GetSurfaceList(SurfaceList_sqlLoadStatment WhereStatment)
        {
            SurfaceList list = new SurfaceList { };
            list.SqlStatment = WhereStatment;
            list.Load();
            return list;
        }

        
        public SurfaceList GetSurfaceList(SurfaceList SurfaceList)
        {
            SurfaceList.Load();
            return SurfaceList;
        }


        
        //public ConstractionList GetConstractionList(ConstractionList.sqlLoadStatment WhereStatment)
        //{
        //    ConstractionList list = new ConstractionList();
        //    list.SqlStatment = WhereStatment;

        //    list.Load();
        //    return list;
        //}


        public ConstractionEntity GetConstraction(string ConstractionID)
        {
            if (!CacheTools.IsCacheObject(ConstractionID))
            {
                ConstractionEntity p = new ConstractionEntity();
                p.ID = ConstractionID;
                //p.SideID = null;
                p.Load();
                CacheTools.SetCacheObject(ConstractionID, p);
                return p;
            }

            return (ConstractionEntity)CacheTools.GetCacheObect(ConstractionID);
        }


        public ConstractionEntity GetConstractionFromSideId(string SideID)
        {

            if (!CacheTools.IsSessionCacheObject(SideID))
            {
                ConstractionEntity p = new ConstractionEntity();
                p.ID = null;
                //p.SideID = SideID;
                p.Load();
                CacheTools.SetSessionCacheObject(SideID, p);
            }
            return (ConstractionEntity)CacheTools.GetSessionCacheObect(SideID);
        }



        public static void Save(ConstractionEntity Constraction)
        {
            string s = Constraction.ID;
            Constraction.Save();
            CacheTools.ResetCache(s);
        }


        public ConstractionEntity SaveConstraction(ConstractionEntity Constraction)
        {
            if (Constraction.ID.IndexOf(AgencyLib_GlobalConstants.qPrefNEW_RECORD) > -1)//режим вставки?
            {
                string s = Constraction.ID;
                Constraction.ID = Constraction.ID.Replace(AgencyLib_GlobalConstants.qPrefNEW_RECORD, "");
                Constraction.Save();
                CacheTools.ResetCache(s);
                return Constraction;
            }

            Constraction.Save();
            return Constraction;
        }


        public ConstractionEntity SaveConstraction_Asyn(ConstractionEntity Constraction)
        {

            Constraction.Save(AppContext.GetSC().ConnectionString);
            Constraction.SetHash();
            return Constraction;

        }



    }
}

